package test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;

import org.apache.log4j.Logger;
import org.eclipse.swt.widgets.Display;

public class Main {
	private static Logger log = Logger.getLogger(Main.class);

	public static ResourceBundle messages;

	public static Properties properties;

	public static void main(String[] args) throws Exception {
		properties = new Properties();
		properties.setProperty("locale", "en");
		properties = new Properties(properties);
		File file = new File("res/app.properties");
		if (!file.exists())
			file.createNewFile();
		InputStream inStream = new FileInputStream(file);
		properties.load(inStream);
		inStream.close();
		messages = ResourceBundle.getBundle("messages", new Locale(properties
				.getProperty("locale")));
		Display display = Display.getDefault();
		Testing thisClass = new Testing();
		thisClass.createSShell();
		thisClass.getSwtShell().open();

		while (!thisClass.getSwtShell().isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();

		OutputStream outStream = new FileOutputStream(file);
		properties.store(outStream, "SWT Testing Application");
		outStream.close();
		log.info(messages.getString("ok"));
	}
}
